package com.lswms.modules.lswms.service.impl.base;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lswms.common.page.PageData;
import com.lswms.common.service.impl.CrudServiceImpl;
import com.lswms.modules.lswms.dao.base.LocationDao;
import com.lswms.modules.lswms.dto.base.LocationDTO;
import com.lswms.modules.lswms.entity.base.LocationEntity;
import com.lswms.modules.lswms.entity.orders.OrderdetaillistEntity;
import com.lswms.modules.lswms.service.base.LocationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 库位
 *
 * @author DX sunlightcs@gmail.com
 * @since 1.0.0 2021-06-04
 */
@Service
public class LocationServiceImpl extends CrudServiceImpl<LocationDao, LocationEntity, LocationDTO> implements LocationService {

    @Override
    public QueryWrapper<LocationEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String location = (String)params.get("location");
        String zonecode = (String)params.get("zonecode");
        String locCategory = (String)params.get("locCategory");
        String locType = (String)params.get("locType");
        String locStatus = (String)params.get("locStatus");

        QueryWrapper<LocationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "lswms_location.id", id);
        wrapper.eq(StringUtils.isNotBlank(location), "lswms_location.location", location);
        wrapper.eq(StringUtils.isNotBlank(zonecode ), "lswms_location.zonecode ", zonecode );
        wrapper.eq(StringUtils.isNotBlank(locCategory), "lswms_location.loc_category", locCategory);
        wrapper.eq(StringUtils.isNotBlank(locType), "lswms_location.loc_type", locType);
        wrapper.eq(StringUtils.isNotBlank(locStatus), "lswms_location.loc_status", locStatus);
        return wrapper;
    }

    @Override
	public PageData<LocationEntity> pageBySql(Map<String, Object> params) {
		IPage<LocationEntity> page = baseDao.selectPageBySql(getPage(params, null, false), getWrapper(params));
		return getPageData(page, LocationEntity.class);
	}

}
